﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InfoPick.Lib.Entity
{
    /// <summary>
    /// 对应于GMDDF和GMODF
    /// </summary>
    public class GMN7LNK
    {
        /// <summary>
        /// 用于排序
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 链路索引
        /// </summary>
        public int LinkIdx { get; set; }

        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 方向
        /// </summary>
        public string Direction
        {
            get
            {
                int last_idx = Name.LastIndexOf('_');
                if (last_idx != -1)
                {
                    return Name.Substring(0, last_idx);
                }
                return Name;
            }
        }

        /// <summary>
        /// 方向
        /// </summary>
        public int NameNum
        {
            get
            {
                int last_idx = Name.LastIndexOf('_');
                if (last_idx != -1)
                {
                    int tmp;
                    if (int.TryParse(Name.Substring(last_idx + 1), out tmp))
                        return tmp;
                }
                return 1;
            }
        }

        /// <summary>
        /// 链路集索引
        /// </summary>
        public int LinkSetIdx { get; set; }

        /// <summary>
        /// MTP2链路号
        /// </summary>
        public int MTP2LinkNo { get; set; }

        public static GMN7LNK Create(string[] row)
        {
            try
            {
                GMN7LNK obj = new GMN7LNK();
                obj.LinkIdx = int.Parse(row[0]);
                obj.Name = row[1];
                obj.LinkSetIdx = int.Parse(row[2]);
                obj.MTP2LinkNo = int.Parse(row[5]);
                return obj;
            }
            catch (Exception e)
            {
                return null;
            }
        }
    }
}
